// https://leetcode.cn/problems/h-index/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int hIndex(vector<int>& citations) {
        sort(citations.begin(), citations.end());

        int res = 0, n = citations.size();
        for (int i = n - 1; i >= 0; i--) {
            if (citations[i] > res) {
                res++;
            }
        }
        return res;
    }
};